package com.weactivity.controller;

import com.weactivity.dto.FeedbackDTO;
import com.weactivity.dto.Result;
import com.weactivity.dto.ShowFeedbackDTO;
import com.weactivity.entity.Report;
import com.weactivity.mapper.ReportMapper;
import com.weactivity.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/feedback")
public class FeedbackController {
    @Autowired(required = false)
    private FeedbackService feedbackService;
    @Autowired(required = false)
    private ReportMapper reportMapper;

    /**
     * 提交反馈
     *
     * @param feedbackDTO
     * @return
     */
    @PutMapping("/submit")
    public Result submit(@RequestBody FeedbackDTO feedbackDTO){
        feedbackService.submit(feedbackDTO);
        return Result.ok();
    }

    /**
     * 生成活动报告
     *
     * @param aid
     * @return
     */
    @PutMapping("/generate")
    public Result generate_re(@RequestParam("aid") int aid){
        feedbackService.generate(aid);
        return Result.ok();
    }

    /**
     * 展示活动报告
     *
     * @param aid
     * @return
     */
    @GetMapping("/show")
    public Result show_re(@RequestParam("aid") int aid){
        Report report = feedbackService.show(aid);
        return Result.ok(report);
    }

    /**
     * 展示活动反馈
     *
     * @param aid
     * @return
     */
    @GetMapping("/showFeedback")
    public Result showFbByAid(@RequestParam("aid") int aid){
        List<FeedbackDTO> feedbackDTOList = feedbackService.selectByAid(aid);
        int subNum = feedbackService.findNumByAid(aid);
        int totalNum = feedbackService.findTotalNumByAid(aid);

        ShowFeedbackDTO showFeedbackDTO = new ShowFeedbackDTO();
        showFeedbackDTO.setFeedbackDTOList(feedbackDTOList);
        showFeedbackDTO.setSubNum(subNum);
        showFeedbackDTO.setTotalNum(totalNum);
        return Result.ok(showFeedbackDTO);

    }


}
